<template>
    <c-list-template :operation="true" title="港口管理">
        <template slot="operation">
            <el-button icon="el-icon-plus" type="primary" @click="handleAdd">新增</el-button>
        </template>
        <template slot="search">
            <el-row :gutter="24">
                <el-col :span="6" class="flex-center">
                    <div class="mr-lg">港口名称：</div>
                    <el-input placeholder="请输入港口名称" v-model="querys.keyword" class="wh flex-1 mr-lg" />
                </el-col>
                <el-col :span="18" class="flex-x-end">
                    <el-button icon="el-icon-search" type="primary" @click="handleSelect">搜索</el-button>
                    <el-button icon="el-icon-delete" @click="handleReset">重置</el-button>
                </el-col>
            </el-row>
        </template>

        <template slot="list">
            <el-table :header-cell-style="{ background: '#F1F1F1', color: '#092132' }" :data="tableData" v-loading="loading">
                <el-table-column align="center" type="index" label="序号" width="80"></el-table-column>
                <el-table-column align="center" prop="country" label="国家" width=""></el-table-column>
                <el-table-column align="center" prop="city" label="城市" width=""></el-table-column>
                <el-table-column align="center" prop="harbor" label="港口名称" width=""></el-table-column>
                <el-table-column align="center" label="创建时间" width="">
                    <template slot-scope="scope">
                        <span>{{ scope.row.timeCreate | dateYMDHMSFormat }}</span>
                    </template>
                </el-table-column>
                <el-table-column align="center" label="操作" width="">
                    <template slot-scope="scope">
                        <el-link type="primary" class="mr-lg" @click="handleEdit(scope.row)">编辑</el-link>
                        <el-link type="danger" class="mr-lg" @click="handleDelete(scope.row)">删除</el-link>
                    </template>
                </el-table-column>
            </el-table>
        </template>
        <template slot="pagination">
            <el-pagination background :current-page="querys.current" :page-sizes="[10, 20, 50, 100]" :page-size="querys.size" layout="total, sizes, prev, pager, next, jumper" :total="total" @size-change="handleSizeChange" @current-change="handleCurrentChange" />
        </template>

        <c-port-form ref="cPortForm" />
    </c-list-template>
</template>

<script>
import cPortForm from "./components/c-port-form.vue";
export default {
    components: {
        cPortForm
    },
    data () {
        return {
            querys: {
                current: 1,
                size: 10
            },
            loading: false,
            tableData: [],
            total: 0,
        };
    },
    mounted () {
        this.tableList()
    },
    methods: {
        handleDelete (item) {
            this.$confirm("是否确认此操作?", "提示", {
                confirmButtonText: "确定",
                cancelButtonText: "取消",
                type: "warning",
            }).then(() => {
                this.$post({
                    url: "/ShopHarborInfo/delete?id=" + item.id,
                }).then(
                    () => {
                        this.$message.success("操作成功");
                        this.tableList()
                    },
                    () => {
                        this.loading = false;
                    }
                );
            })
        },
        handleSelect () {
            this.querys.current = 1;
            this.tableList();
        },
        handleReset () {
            this.querys = {
                current: 1,
                size: 10,
            };
            this.tableList();
        },
        handleSizeChange (val) {
            this.querys.size = val;
            this.tableList();
        },
        handleCurrentChange (val) {
            this.querys.current = val;
            this.tableList();

        },
        tableList () {
            this.loading = true;
            const params = JSON.parse(JSON.stringify(this.querys));
            const url = "/ShopHarborInfo/page";
            this.$get({ url, params }).then((res) => {
                this.tableData = res.records
                this.total = res.total * 1;
                this.loading = false;
            });
        },
        handleEdit (item) {
            this.$refs.cPortForm.handleOpen(item);
        },
        handleAdd () {
            this.$refs.cPortForm.handleOpen();
        }
    }
};
</script>
<style scoped lang="scss">
</style>
